package LeetCode.month02.day40;

public class No209 {
    public static void main(String[] args) {
        System.out.println(minSubArrayLen(7,new int[]{2,3,1,2,4,3}));
    }
    public static int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0;
        int sum = 0;
        int res = n+1;
        for (int right = 0; right <n; right++) {
            sum+=nums[right];
            if(sum>=target){
                while(sum>=target){
                    res = Math.min(res,right-left+1);
                    sum-=nums[left++];
                }
            }
        }
        return res==n+1?0:res;
    }
}
